<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2024/1/27
  Time: 15:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<html>
<head>
    <title>个人中心</title>
    <link rel="stylesheet" href="css/center.css">
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/center.js"></script>
</head>
<body>
<%@include file="header.jsp" %>
<section>
    <ul class="bg">
        <li class="left-top">
            <ul>
                <li class="left_top_a btn" data-target="element1">个人资料</li>
                <li class="btn" data-target="element2">账户设置</li>
                <li class="btn" data-target="element3">关注中心</li>
                <li class="btn" data-target="element4">我的订单</li>
                <li class="btn" data-target="element5">浏览历史</li>
            </ul>
        </li>
        <li class="right-top">
            <div id="element1" class="element">
                <div class="basic-top">基本信息</div>
            </div>

            <div class="modify u-headImg">
                <div class="modify-top"><span>修改头像</span><span onclick="show_and_hide('.u-headImg')">×</span></div>
                <div class="line">
                    <div class="modify-center">
                        <img src="" id="headImg"/>
                        <label class="upload-label" for="avatar"></label>
                        <input type="file" id="avatar" name="avatarImg" accept="image/*" required style="display: none;">
                    </div>
                    <div class="modify-footer">
                        <a class="btn-confirm">修改</a>
                        <a href="#" class="btn-cancel" onclick="show_and_hide('.u-headImg')">取消</a>
                    </div>
                </div>
            </div>
            <div id="element2" class="element">
                <div class="basic-top">账户设置</div>
                <div class="user_basic">
                    <div class="basic">修改密码：<span class="modify-u-pass"
                                                  onclick="show_and_hide('.user-account-content')">立即修改</span>
                    </div>
                    <div class="basic">实名认证：<span class="modify-u-identity"
                                                  onclick="show_and_hide('.u-identity')">立即认证</span>
                    </div>
                    <div class="basic">手机认证：<span class="modify-u-phone" onclick="show_and_hide('.u-phone')">立即认证</span>
                    </div>
                    <div class="basic">账户注销：<span class="modify-u-del" onclick="show_and_hide('.u-del')">立即注销</span>
                    </div>
                </div>
                <div class="modify u-del">
                    <div class="modify-top"><span>注销账户</span><span onclick="show_and_hide('.u-del')">×</span></div>
                    <div class="modify-center">
                        <p>
                            账号注销则视为您主动放弃以下资产和权益，且同意以下规则：</p>
                        <p>1.账号注销后，您将无法登录、使用旗木账号，且不支持找回任何个人资料。</p>
                        <p>2.将不再支持使用已注销账号的用户ID注册新的账号。</p>
                        <p>3.注销旗木账号并不代表您注销前的账号行为和相关责任得到豁免或减轻。</p>
                    </div>
                    <div class="modify-footer">
                        <a class="btn-confirm cancel">注销</a>
                        <a href="#" class="btn-cancel" onclick="show_and_hide('.u-del')">取消</a>
                    </div>
                </div>
                <div class="modify user-account-content">
                    <div class="modify-top"><span>修改密码</span><span
                            onclick="show_and_hide('.user-account-content')">×</span>
                    </div>
                    <div class="modify-center">
                        <ul class="old">
                            <li class="old-li">
                                <label for="old-password">旧&nbsp;&nbsp;密&nbsp;码：</label>
                                <input type="password" id="old-password" name="OriginalPassword" placeholder="请输入原密码"/>
                            </li>
                            <li class="old-li">
                                <label for="new-password">新&nbsp;&nbsp;密&nbsp;码：</label>
                                <input type="password" id="new-password" name="password"
                                       placeholder="至少一个字母与数字组成，长度8-12"/>
                            </li>
                            <li class="old-li">
                                <label for="confirm-password">确认密码：</label>
                                <input type="password" id="confirm-password" name="confirmPassword" placeholder="确认密码"/>
                            </li>
                        </ul>
                    </div>
                    <div class="modify-footer">
                        <a class="btn-confirm userPwd">修改</a>
                        <a href="#" class="btn-cancel" onclick="show_and_hide('.user-account-content')">取消</a>
                    </div>
                </div>
                <div class="modify u-phone">
                    <div class="modify-top"><span>手机验证</span><span onclick="show_and_hide('.u-phone')">×</span>
                    </div>
                    <div class="modify-center">
                        <ul class="old">
                            <li class="old-li">
                                <label for="old-phone">手机号码：</label>
                                <input type="number" id="old-phone" name="phone" placeholder="请输入11位手机号码"/>
                            </li>
                        </ul>
                    </div>
                    <div class="modify-footer">
                        <a class="btn-confirm phone">验证</a>
                        <a href="#" class="btn-cancel" onclick="show_and_hide('.u-phone')">取消</a>
                    </div>
                </div>
                <div class="modify u-identity">
                    <div class="modify-top"><span>实名验证</span><span onclick="show_and_hide('.u-identity')">×</span>
                    </div>
                    <div class="modify-center">
                        <ul class="old">
                            <li class="old-li">
                                <label for="old-phone">身份证号码:</label>
                                <input type="text" id="old-identity" name="idCard" placeholder="请输入18位身份证号码"/>
                            </li>
                            <li class="old-li">
                                <label for="old-phone">真&nbsp;实&nbsp;姓&nbsp;名:</label>
                                <input type="text" id="old-real" name="realName" placeholder="请输入真实名字"/>
                            </li>
                        </ul>
                    </div>
                    <div class="modify-footer">
                        <a class="btn-confirm idCard">验证</a>
                        <a href="#" class="btn-cancel" onclick="show_and_hide('.u-identity')">取消</a>
                    </div>
                </div>
            </div>
            <div id="element3" class="element">
                <div class="basic-top">我的关注</div>
                <ul class="tab-trigger">
                    <li class="trig-item concern-and-commodity"><a href="#" class="text">关注的商品</a></li>
                    <li class="trig-item concern-and-store"><a href="#" class="text">关注的店铺</a></li>
                </ul>
                <div class="div_recommend">
                    <ul class="ul_recommend concern">
                        <div class="concern_commodity"></div>
                        <div class="concern_store"></div>
                    </ul>
                </div>
            </div>

            <div id="element4" class="element">
                <div class="basic-top">我的订单</div>
                <div class="order-box">

                    <div class="modify order-identity">
                    <div class="modify-top"><span>评论商品</span><span onclick="show_and_hide('.order-identity')">×</span>
                    </div>
                    <div class="modify-center">
                        <ul class="old">
                            <input type="hidden" value="" id="concern-commodityId">
                            <li class="old-li">
                                <label class="order-label">评论内容:</label>
                                <textarea type="text" id="order-identity" name="idCard" placeholder="请输入评论内容"></textarea>
                            </li>
                            <li>
                                <ul class="comment-img">
                                    <li>
                                        <label>评论照片：</label>
                                    </li>
                                    <li>
                                        <img src="" class="commentImg" />
                                        <label class="upload-label-comment" for="fileInput1"></label>
                                        <input type="file" id="fileInput1" onclick="commentImg('#fileInput1')" name="commentImg" accept="image/*" required style="display: none;" />
                                    </li>
                                    <li>
                                        <img src="" class="commentImg" />
                                        <label class="upload-label-comment" for="fileInput2"></label>
                                        <input type="file" id="fileInput2" onclick="commentImg('#fileInput2')" name="commentImg" accept="image/*" required style="display: none;" />
                                    </li>
                                    <li>
                                        <img src="" class="commentImg" />
                                        <label class="upload-label-comment" for="fileInput3"></label>
                                        <input type="file" id="fileInput3" onclick="commentImg('#fileInput3')" name="commentImg" accept="image/*" required style="display: none;" />
                                    </li>
                                </ul>
                                <script>
                                    function commentImg(el) {
                                        $(el).on('input', () => {
                                            var windowURL = window.URL || window.webkitURL;
                                            var dataURL = windowURL.createObjectURL($(el)[0].files[0]);
                                            $(el).prevAll(".commentImg").attr('src', dataURL);
                                            $(el).prevAll(".commentImg").show();
                                            $(el).prevAll(".upload-label-comment").hide();
                                        })
                                    }
                                </script>
                            </li>
                        </ul>
                    </div>
                    <div class="modify-footer">
                        <a class="btn-confirm order-button">评论</a>
                        <a href="#" class="btn-cancel" onclick="show_and_hide('.order-identity')">取消</a>
                    </div>
                </div>
                </div>
            </div>
            <div id="element5" class="element">
                <div class="basic-top">浏览历史</div>
                <div class="div_recommend">
                    <ul class="ul_recommend browsingHistory">
                        <p class="html-msg"></p>
                    </ul>
                </div>
            </div>
        </li>
    </ul>
</section>
<%@include file="footer.jsp" %>
</body>
</html>
<script>
    window.onload = function () {
        let user = localStorage.getItem("userJson");
        user = eval('(' + user + ')');
        findUser(user.userId); // 用户信息
        getOrderUsers(user.userId); // 我的订单
        getBrowsingHistory(user.userId)// 历史记录
        getConcern(user.userId) // 关注中心
    }
    const element1 = $("#element1");
    let htmlUser = "";

    function findUser(userId) {
        $.ajax({
            type: "post",
            url: "user/getUser",
            data: {
                userId: userId
            },
            success: function (res) {
                if (res.msg == "success") {
                    htmlUser =
                        "<ul><li class=\"u_details\">" +
                        "<div class=\"u_img\"><img src='../" + res.user.headImg + "' onclick=\"show_and_hide('.u-headImg')\"></div>" +
                        "<div class=\"nickname\">" + res.user.nickName + "</div>" +
                        "<div class=\"exit\"><a id='exit'>退出登录</a></div>" +
                        "</li> <li class=\"elements\"><div class=\"u_element\">" +
                        "<div class=\"basic\">用户昵称：<input type=\"text\" value='" + res.user.nickName + "' class=\"nick_name\"></div>" +
                        "<div class=\"basic\">用户账户：<input type=\"text\" value='" + res.user.username + "' class=\"username\"></div>";
                    const u_identity = res.user.idCard;
                    if (u_identity != null) {
                        htmlUser += "<div class=\"basic\">用户年龄：<span class=\"age\">" + idCard(u_identity, 3) + "</span></div>" +
                            "<div class=\"basic\">用户性别：<span class=\"sex\">" + idCard(u_identity, 2) + "</span></div>" +
                            "<div class=\"basic\">出生日期：<span class=\"birth\">" + idCard(u_identity, 1) + "</span></div>" +
                            "</div><button class=\"form-save-btn\">保存</button></li></ul>";
                    } else {
                        htmlUser +=
                            "<div class=\"basic\">用户年龄：<span class=\"age\">未设置</span></div>" +
                            "<div class=\"basic\">用户性别：<span class=\"sex\">未设置</span></div>" +
                            "<div class=\"basic\">出生日期：<span class=\"birth\">未设置</span></div>" +
                            "</div><button class=\"form-save-btn\">保存</button></li></ul>";
                    }
                    element1.append(htmlUser);

                    $("#exit").click(function () {
                        $.ajax({
                            type: "Get",
                            url: "user/exit",
                            success: function (res) {
                                if (res == "success") {
                                    localStorage.removeItem("userJson");
                                    window.location.href = "index.jsp";
                                }
                            }
                        })
                    });
                }
                // 修改账号和昵称
                $(".form-save-btn").click(function () {
                    const nickName = $(".nick_name").val();
                    const username = $(".username").val();
                    $.ajax({
                        type: "Post",
                        url: "user/updateName",
                        data: {
                            userId: userId,
                            nickName: nickName,
                            username: username
                        },
                        success: function (res) {
                            if (res == "success") {
                                alert("保存成功！")
                            } else if (res == "fail") {
                                alert("保存失败！")
                            }
                        },
                        error: function () {
                            alert("error")
                        }
                    })
                });
                // 修改密码
                $(".userPwd").click(function () {
                    const old_pwd = $("#old-password").val(); // 原密码
                    const new_pwd = $("#new-password").val(); // 新密码
                    const confirm_pwd = $("#confirm-password").val(); // 确认密码
                    if (old_pwd != null && new_pwd == confirm_pwd) {
                        $.ajax({
                            type: "post",
                            url: "user/modifyUserPwd",
                            data: {
                                userId: userId,
                                newPwd: new_pwd,
                                oldPwd: old_pwd
                            },
                            success: function (res) {
                                if (res == "success") {
                                    alert("修改成功")
                                    $(".user-account-content").toggle();
                                } else if (res == "fail") {
                                    alert("修改失败")
                                }
                            },
                            error: function () {
                                alert("error")
                            }
                        })
                    } else if (new_pwd != confirm_pwd) {
                        alert("两次密码不相同")
                    } else if (old_pwd == new_pwd) {
                        alert("原密码与新密码重复")
                    }
                });
                // 实名验证
                $(".idCard").click(function () {
                    const old_identity = $("#old-identity").val();
                    const old_real = $("#old-real").val();
                    $.ajax({
                        type: "post",
                        url: "user/addIdCard",
                        data: {
                            idCard: old_identity,
                            realName: old_real,
                            userId: userId
                        },
                        success: function (res) {
                            if (res == "success") {
                                alert("验证成功")
                                $(".u-identity").toggle();
                            } else if (res == "existed") {
                                alert("身份已被验证")
                            } else if (res == "fail") {
                                alert("验证失败")
                            }
                        },
                        error: function () {
                            alert("error")
                        }
                    })
                });
                // 手机号验证
                $(".phone").click(function () {
                    const old_phone = $("#old-phone").val();
                    $.ajax({
                        type: "post",
                        url: "user/addPhone",
                        data: {
                            userId: userId,
                            phone: old_phone
                        },
                        success: function (res) {
                            if (res == "success") {
                                alert("验证成功")
                                $(".u-phone").toggle();
                            } else if (res == "existed") {
                                alert("手机号已被验证")
                            } else if (res == "fail") {
                                alert("验证失败")
                            }
                        },
                        error: function () {
                            alert("error")
                        }
                    })
                });

                $(".cancel").click(function () {
                    confirmLogout();
                })

                function confirmLogout() {
                    const isConfirmed = confirm("您确定要注销吗？");
                    if (isConfirmed) {
                        $.ajax({
                            type: "post",
                            url: "user/userCancel",
                            data: {
                                userId: userId
                            },
                            success: function (res) {
                                if (res == "success") {
                                    alert("注销成功")
                                    localStorage.removeItem("userJson");
                                    window.location.href = "login.jsp";
                                } else if (res == "fail") {
                                    alert("注销失败")
                                }
                            },
                            error: function () {
                                alert("error")
                            }
                        })
                    } else {
                        // 如果用户点击“取消”，可以提示用户取消注销操作
                        alert("注销已取消！");
                    }
                }
            }
        })
    }
    const browsingHistory = $(".browsingHistory");
    const htmlMsg = $(".browsingHistory .html-msg");
    let htmlBrowsingHistory = [];
    let htmlCollect = [];
    let htmlCommodityBrowsingHistory = [];
    function getBrowsingHistory(userId) {
        $.ajax({
            type: "post",
            url: "browsingHistory/getBrowsingHistoryUser",
            data: {
                userId: userId
            },
            dataType: "json",
            success: function (res) {
                if (res.msg == "success") {
                    for (let j = 0; j < res.data.length; j++) {
                        const j_dateTime = res.data[j].browsingHistoryTime;
                        const j_parts = j_dateTime.split(" ");
                        const j_date = j_parts[0];
                        const parts = j_dateTime.split("-");
                        const year = parts[0].split("").join("");
                        const month = parts[1].split("").join("");
                        const day = parts[2].split(" ")[0];
                        htmlBrowsingHistory.push("<div class='browsingHistory_li'>" +
                            "<p class=\"show-date\">" + year + "年" + month + "月" + day + "日</p>");
                        for (let i = 0; i < res.data.length; i++) {
                            const i_dateTime = res.data[i].browsingHistoryTime;
                            const i_parts = i_dateTime.split(" ");
                            const i_date = i_parts[0];
                            if (j_date == i_date) {
                                htmlCollect.push("<a href='/patMall/commodityDetails.jsp?commodityId=" + res.data[i].commodity.commodityId + "'>" +
                                    "<li class=\"li_recommend\" title='" + res.data[i].commodity.commodityName + "'>" +
                                    "<input type=\"hidden\" value='" + res.data[i].browsingHistoryTime + "' class=\"time\">" +
                                    "<img src='../" + res.data[i].commodity.commodityImgList[0].commodityImg + "' class=\"li_img\">" +
                                    "<p class=\"li_p\">" + res.data[i].commodity.commodityName + "</p>" +
                                    "<p class=\"money\">￥" + res.data[i].commodity.commodityPrice + "</p><div class=\"operate\">" +
                                    "<a href='buyCommodity.jsp?commodityId=" + res.data[i].commodity.commodityId + "' class=\"purchase\">购买</a>" +
                                    "<a href='#' class=\"delete\">删除</a></div></li></a>");
                                $(".show-date").text()
                            } else {
                                continue;
                            }
                        }
                        htmlBrowsingHistory.push(unique(htmlCollect));
                        htmlBrowsingHistory.push("</div>");
                        htmlCommodityBrowsingHistory.push(unique(htmlBrowsingHistory).join(""));
                        htmlCollect = [];
                        htmlBrowsingHistory = [];
                    }
                    browsingHistory.append(unique(htmlCommodityBrowsingHistory).join(""));

                    function unique(arr) {
                        return Array.from(new Set(arr))
                    }
                } else if (res.msg == "fail") {
                    browsingHistory.append("<p>没有历史记录</p>");
                } else if (res.msg == "NoFound") {
                    browsingHistory.append("<p>没有商品</p>");
                }
            },
            error: function () {
                alert("Error");
            }
        })
    }

    //通过身份证号计算年龄、性别、出生日期
    function idCard(userCard, num) {
        //获取出生日期
        var birth;
        if (num == 1) {
            birth = userCard.substring(6, 10) + "-" + userCard.substring(10, 12) + "-" + userCard.substring(12, 14);
            return birth;
        }
        //获取性别
        if (num == 2) {
            if (parseInt(userCard.substr(16, 1)) % 2 == 1) {
                return "男";
            } else {
                return "女";
            }
        }
        //获取年龄
        if (num == 3) {
            var myDate = new Date();
            var month = myDate.getMonth() + 1;
            var day = myDate.getDate();
            var age = myDate.getFullYear() - userCard.substring(6, 10) - 1;
            if (userCard.substring(10, 12) < month || userCard.substring(10, 12) == month && userCard.substring(12, 14) <= day) {
                age++;
            }
            return age;
        }
    }
    let htmlConcernCommodity ="";
    let htmlConcernStore ="";
    const concernCommodity = $(".concern .concern_commodity");
    const concernStore = $(".concern .concern_store")
    //关注商品
    function getConcern(userId){
        $.ajax({
            type:"post",
            url:"concern/getConcernUser",
            data:{
                userId:userId
            },
            success:function (res) {
                console.log(res)
                if (res.msg == "success"){
                    htmlConcernCommodity = "<div class='concern-commodity'>"
                    for (let i = 0; i < res.data.length; i++) {
                        if(res.data[i].commodityId != null) {
                            htmlConcernCommodity +=
                                "<a href='/patMall/commodityDetails.jsp?commodityId=" + res.data[i].commodity.commodityId + "'>" +
                                "<li class=\"li_recommend\" title='" + res.data[i].commodity.commodityName + "'>" +
                                "<input type=\"hidden\" value='" + res.data[i].browsingHistoryTime + "' class=\"time\">" +
                                "<img src='../" + res.data[i].commodity.commodityImgList[0].commodityImg + "' class=\"li_img\">" +
                                "<p class=\"li_p\">" + res.data[i].commodity.commodityName + "</p>" +
                                "<p class=\"money\">￥" + res.data[i].commodity.commodityPrice + "</p><div class=\"operate\">" +
                                "<a href='buyCommodity.jsp?commodityId=" + res.data[i].commodity.commodityId + "' class=\"purchase\">购买</a>" +
                                "<a href='#' class=\"delete\">删除</a></div></li></a>";
                        }
                    }
                    htmlConcernCommodity += "</div>";
                    for (let i = 0; i < res.data.length; i++) {
                        if (res.data[i].storeId != null) {
                            htmlConcernStore +=
                                "<div class=\"concern-store\">" +
                                "<a href='storeCenter.jsp?storeId=" + res.data[i].store.storeId + "'>" +
                                "<li title='" + res.data[i].store.storeName + "' class=\"li-store\">" +
                                "<img src='../" + res.data[i].store.storeImg + "'>" +
                                "<p>" + res.data[i].store.storeName + "</p><a href='#' class=\"delete_store\">删除</a></li></a></div>";
                        }
                    }
                    concernCommodity.append(htmlConcernCommodity);
                    concernStore.append(htmlConcernStore);
                }else if (res.msg == "fail"){
                    concern.append("<p>未关注任何商品</p>");
                }
                $(".concern-and-commodity").click(function (){
                    $(".concern_commodity").show();
                    $(".concern_store").hide();
                })
                $(".concern-and-store").click(function (){
                    $(".concern_commodity").hide();
                    $(".concern_store").show();
                })
            },
            error:function () {
                alert("error")
            }
        })
    }
    // 我的订单
    function getOrderUsers(userId) {
        let htmlOrderUser = "";
        const order_box = $(".order-box");
        $.ajax({
            type: "post",
            url: "order/getOrderUsers",
            data: {
                userId: userId
            },
            success: function (res) {
                for (let i = 0; i < res.data.length; i++) {
                    htmlOrderUser =
                        "<div class=\"orderUser\">" +
                        "<div class=\"order-head\">" +
                        "<span class=\"order-date\">" + res.data[i].orderId + "</span>" +
                        "<span class=\"order-id\">订单号：" + res.data[i].orderId + "</span>" +
                        "<span class=\"order-delete\">*</span>" +
                        "</div>" +
                        "<div class=\"order-body\"><div class=\"poster\">" +
                        "<img src='../" + res.data[i].commodity.commodityImgList[0].commodityImg + "'></div>" +
                        "<div class=\"order-content\">" +
                        "<div class=\"movie-name\">" + res.data[i].commodity.commodityName + "</div>" +
                        "<div class=\"cinema-name\"><a href=\"#\">" + res.data[i].commodity.store.storeName + "</a></div>" +
                        "<div class=\"hall-ticket\">数量：" + res.data[i].number + "</div>" +
                        "<div class=\"show-time\">" + res.data[i].orderTime + "</div></div>" +
                        "<div class=\"order-price\">￥" + res.data[i].totalAmount + "</div>";
                    if (res.data[i].state == 1) {
                        htmlOrderUser +=
                            "<div class=\"order-status\">已退货</div>";
                    } else if (res.data[i].state == 2) {
                        htmlOrderUser +=
                            "<div class=\"order-status\">审核中</div>";
                    } else {
                        htmlOrderUser +=
                            "<div class=\"order-status\">已购买</div>";
                    }
                    htmlOrderUser += "<input type='hidden' class='order_id' value='"+res.data[i].orderId+"'><input type='hidden' class='commodityId' value='"+res.data[i].commodity.commodityId+"'>" +
                        "<div class=\"comment_commodity\" onclick=\"showAndHide('.order-identity',"+res.data[i].commodity.commodityId+")\">" +
                        "<a style=\"cursor: pointer;\">评价商品</a></div><div class=\"actions\">" +
                        "<a href=\"#\" style=\"cursor: pointer;\">申请退货</a></div></div></div>";
                    order_box.prepend(htmlOrderUser);
                }
                $(".actions").click(function () {
                    if ($(this).prevAll('.order-status').first().text() == "审核中"){
                        alert("正在审理中");
                    }else if ($(this).prevAll('.order-status').first().text() == "已退货"){
                        alert("已退货成功")
                    }else if ($(this).prevAll('.order-status').first().text() == "已购买"){
                    const isConfirmed = confirm("您确定要退货吗？");
                        const  orderId = $(this).prevAll('.order_id').first().val();
                    if (isConfirmed) {
                        $.ajax({
                            type: "post",
                            url: "order/updateOrder",
                            data: {
                                orderId: orderId
                            },
                            success: function (res) {
                                if (res == "success") {
                                    alert("退货成功")
                                    order_box.empty();
                                    getOrderUsers(userId);
                                } else if (res == "fail") {
                                    alert("退货失败")
                                }
                            },
                            error: function () {
                                alert("error")
                            }
                        })
                    } else {
                        alert("退货已取消！");
                    }
                    }else {
                        alert("系统错误，无法退货！")
                    }
                })
            },
            error: function () {
                alert("error")
            }
        })
    }// 当上传按钮被点击时
    $('.order-button').click(function() {
        const formData = new FormData();
        // 假设您有3个文件输入框，分别命名为 fileInput1, fileInput2, fileInput3
        for (let i = 1; i <= 3; i++) {
            // 选择文件输入框
            const fileInput = $("#fileInput" + i)[0];
            // 获取文件列表
            const files = fileInput.files;
            if (files.length > 0) {
                // 为每个文件设置唯一的键名
                formData.append("files" + i, files[0]); // 假设我们只上传每个输入框的第一个文件
            }
        }
        let user = localStorage.getItem("userJson");
        user = eval('(' + user + ')');
        const userId = user.userId;
        let commodityId = $("#concern-commodityId").val();
        formData.append("userId", userId);
        formData.append("commodityId", commodityId);
        formData.append("commentContent", $("#order-identity").val());
        $.ajax({
            type: 'POST',
            url: 'comment/addComment', // 你的上传接口URL
            data: formData,
            processData: false,
            contentType: false,
            success: function(res) {
                if (res.code == 0){
                    alert("评论成功")
                    $(".order-identity").toggle();
                }else if(res.code == 1){
                    alert("评论失败")
                    $(".order-identity").toggle();
                }
            },
            error: function() {
                alert("error");
            }
        });
    });
    function showAndHide(el,commodityId){
        $(el).toggle();
        $("#concern-commodityId").val(commodityId);
    }
</script>